import {Component} from '@angular/core';
import {IonicPage, AlertController, NavController, NavParams} from 'ionic-angular';
import {UtilsProvider} from "../../providers/utils/utils";
import {HttpServicesProvider} from "../../providers/http-services/http-services";
import {ValidateProvider} from "../../providers/validate/validate";
import {ConfigProvider} from "../../providers/config/config";
import {CommonProvider} from "../../providers/common/common";

@IonicPage({
    segment: 'service/talent_pool/resume_detail/:resume_id',
    defaultHistory: ['HomePage','TalentPoolSearchPage']
})
@Component({
    selector: 'page-resume-detail',
    templateUrl: 'resume-detail.html',
})
export class ResumeDetailPage {
    resume_id:number;
    resume = {};
    // 收藏状态
    collected: boolean = false;
    constructor(
        public navCtrl: NavController,
        public navParams: NavParams,
        public httpService: HttpServicesProvider,
        public validate: ValidateProvider,
        public config: ConfigProvider,
        public util: UtilsProvider,
        public alertCtrl: AlertController,
        public common: CommonProvider
    ) {
        if (!this.validate.checkLogin()) {
            this.navCtrl.push('LoginPage');
        }
    }

    //判断用户是否登录
    ionViewCanEnter() {
        return this.validate.checkLogin();
    }

    ionViewDidLoad() {
        this.resume_id = this.navParams.get('resume_id');
        this.getResume();
    }

    // 是否收藏简历
    collect(amoy_id){
        let collectUrl = '/talents/resume_collect'
        this.httpService.requestPostData(collectUrl, {
            token: this.config.getToken(),
            resume_id: this.resume_id
        }, response => {
            if (response['code'] === 200) {
                this.util.presentAlert(response['message']);
                this.getResume()
            } else {
                this.util.presentAlert(response['message']);
            }
        });
    }
    // 查看简历
    getResume() {
        let apiUrl = "/talents/resume_detail";
        this.httpService.requestPostData(apiUrl, {
            token: this.config.getToken(),
            resume_id: this.resume_id
        }, response => {
            if (response['error'] === 200) {
                this.resume = response['data'];
                this.collected = this.resume['has_collect']
            } else {
                this.util.presentAlert(response['message']);
            }
        });
    }

    getTel(){
        this.util.presentConfirm('当前内容为付费查看内容，您需要支付1元', ()=>{
            let postData = {
                resume_id: this.resume_id,
                token: this.config.getToken()
            };
            this.httpService.requestPostData('/talents/resume_pay', postData, (response)=>{
                if(response['error'] == 200){
                    this.util.presentAlert('付费成功');
                    this.getResume();
                }else if(response['error'] == 300){
                    this.util.presentConfirm('当前账户余额不足，现在去充值？',()=>{
                        // this.storage.set('backPage',JSON.stringify({page: 'InformationDetailPage', params: {amoy_id: this.amoy_id}}));
                        this.common.setBackPage('ResumeDetailPage',{resume_id:this.resume_id});
                        this.navCtrl.push('MoneyRechargePage');
                    })
                }
            })
        }, ()=>{
    
        });
                            
       


    }
}
